<html>
<head>
<title> View personal details for a staff</title>
<body>
<?php
if( isset( $_POST['staff_id'] ) ) {

	PutEnv("ORACLE_HOME=/usr/local/dbpackages/oracle");

	$c = oci_connect('comp231stu032', 'chemistry', 'comp231.cse.ust.hk');

	if(!$c) {
		echo "<p>Unable to connect:" . var_dump(oci_error($c));
		die();
	}

	$s = 'SELECT * FROM STAFF WHERE ID=' . $_POST['staff_id'];

	$q = oci_parse($c, $s);

	oci_execute($q);

	echo "
	<h1>Welcome to the 231chefs Roster Generation System</h1>
	<h2>View Staff</h2>";
if(oci_fetch($q)) {
	echo "
	<table cellpadding='5' cellspacing='0' border='1'>
	<tr><td>Staff ID</td><td>". oci_result($q, "ID"). "</td></tr>
	<tr><td>Surname</td><td>" .oci_result($q, "SURNAME"). "</td></tr>
	<tr><td>Given name</td><td>" .oci_result($q, "GIVEN_NAME"). "</td></tr>";


//working status ------------------------------
	$state = "";
	switch (oci_result($q,"WORKING_STATUS")) {
		case "AV":	$state = "Available";break;
		case "SL":	$state = "Sick Leave";break;
		case "AL":	$state = "Annual Leave";break;
		case "DO":	$state = "Day Off";break;
		case "ST":	$state = "Statutory Leave";break;
	}	
	echo "<tr><td>Working status</td><td> $state </td></tr>";

//working time slot ----------------------------

	$time_slot = "";
	$time_code = oci_result($q,"WORKING_TIME_SLOT");
	switch ($time_code) {
		case "MA":	$time_slot = "05:00 - 14:00";
				break;
		case "AA":	$time_slot = "12:00 - 21:00";
				break;
		case "EA":	$time_slot = "15:00 - 24:00";
				break;
	}
	echo "<tr><td>Working time slot</td><td>$time_code $time_slot </td></tr>";
//skill list ------------------
	$tsl = (int)(oci_result($q,"SKILL_LIST"));
	$arr = array(1, 2, 4, 8, 16);
	$arrskill = array ('Boeing 747', 'Boeing 757', 'Boeing 777', 'AirBus 340', 'AirBur 380');
	$skill = '';
	for($i = 0; $i < 5; $i++) {
		if($arr[$i] & $tsl) {
		$skill = $skill." ". $arrskill[$i];
		}
	}
	echo "<tr><td>Skill list</td><td>$skill</td></tr>";

//-----------------------------------

	echo "<tr><td>Reward per hour</td><td>". oci_result($q, "REWARD_PER_HALF_HR")."</td></tr>";
	echo "</table>";
}
else
	echo "The Staff id does no exist<br>";

	echo "<p>Click <a href='index.php'>here</a> to return to the Main Menu</p>";
	oci_close($c);

}
else {
	echo "
	<form action='personal.php' method='POST'>
	Staff ID: <input name='staff_id' maxlength='5' />
	<button type='submit'>Show</button>
	</form>";
}
?>
</body>
<html>


